function [xk,fk] = nmlinesearch(fun,x,d,nablaf,fval)
    c1 = 5*1.0e-4; 
    ls = 0; 
    beta = 0.618;
    f0 = fval; 
    g = nablaf;
    alpha = 1.0; 
    xk = x + alpha*d;
    fk = feval(fun,xk);
    rh = f0 + c1*alpha*g'*d;
while(fk>rh)&&(ls<20)
    alpha = alpha*beta; 
    xk = x + alpha*d;
    fk = feval(fun,xk);
    rh = f0 + c1*alpha*g'*d;
    ls = ls+1; 
end

